import java.util.Scanner;
public class Complex {
	private double rea;
    private double ima;
    public Complex(final double rea,final double ima)
    {
    	this.rea=rea;	
    	this.ima=ima;
    }
    public Complex(final double rea)
    {
        this.rea=rea;
        this.ima=0;
    }
    public Complex()
    {
        this(0,0);
    }
    public Complex(Complex com)
    {
        this.rea=com.rea;
        this.ima=com.ima;
    }
    public Complex(final String str)
    {
        this(0,0);
        MyScanner scan=new MyScanner(str);
        double re=scan.nextScience(true);
        if(scan.ifLastSuccess())
        {
            double im=scan.nextScience(false);
            if(scan.nextChar()=='i'||!scan.ifLastSuccess())
            {
                rea=re;
                ima=im;
            }
        }
    }
    public static Complex add(final Complex a,final Complex b)
    {
        return new Complex(a.rea+b.rea,a.ima+b.ima);
    }
    public static Complex minus(final Complex a, final Complex b)
    {
        return new Complex(a.rea-b.rea,a.ima-b.ima);
    }
    public static String toString(final Complex a)
    {
        String reas=String.format("%.8f",a.rea);
        String imas=String.format("%.8f",a.ima);
        return ((a.rea==0)?"":reas)+((a.ima==0)?"":(""+((a.ima>=0)?("+"+imas):(""+imas))))+"i";
    }
    public static boolean equals(final Complex a,final Complex b)
    {
        return a.rea==b.rea&&a.ima==b.ima;
    }
    public static double length(final Complex a)
    {
        return Math.sqrt(a.rea*a.rea+a.ima*a.ima);
    }
    public Complex add(final Complex a)
    {
        return add(this,a);
    }
    public Complex minus(final Complex a)
    {
        return add(this,a);
    }
    public String toString()
    {
        return toString(this);
    }
    public boolean equals(final Complex a)
    {
        return equals(this,a);
    }
    public double length()
    {
        return length(this);
    }
}
